import socket
import time
from datetime import datetime

def send_udp_packet():
    # 目标地址和端口
    target_ip = "127.0.0.1"
    target_port = 8778
    
    # 创建UDP套接字
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    
    # 要发送的数据 - 单个字节0x01
    data = bytes([0x01])  # 等同于 b'\x01'

    while True:
        current_time = datetime.now()
        print("当前时间是：", current_time)
        if current_time.hour == 15 and current_time.minute == 30:
            try:
                # 发送数据
                sock.sendto(data, (target_ip, target_port))
                print(f"已发送1字节数据: {data.hex()} 到 {target_ip}:{target_port}")
                break
            except Exception as e:
                print(f"发送失败: {e}")
            finally:
                # 关闭套接字
                sock.close()
        time.sleep(10)

if __name__ == "__main__":
    send_udp_packet()
